package com.jiepos.mpos.biz.channel.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.jiepos.mpos.biz.channel.service.HostLargeService;
import com.jiepos.mpos.biz.channel.service.InfChannelService;
import com.jiepos.mpos.common.entity.App_Host_LargeEntity;
import com.jiepos.mpos.core.controller.BaseController;
import com.jiepos.mpos.core.entity.Pagination;
import com.jiepos.mpos.core.util.StringUtils;

/**
 * 
 * 
 * <p>标题: —— 大商户表控制器</p>
 * <p>模块: 通用平台</p>
 * <p>版权: Copyright (c) 2017 江苏杰博实信息技术有限公司
 * @ProjectName:  [mpos] 
 * @Package com.jiepos.mpos.biz.channel.controller 
 * @author 张学涛
 * @version 1.0
 * @since 2017年9月27日下午2:22:48
 * @history（历次修订内容、修订人、修订时间等）
 */
@Controller
@RequestMapping("hostlarge")
public class HostLargeController extends BaseController {
	
	@Autowired
	private HostLargeService hostLargeService;
	@Autowired
	private InfChannelService infChannelService;
	
	
	/**
	 * 进入大商户列表页面
	 * @param request
	 * @param response
	 * @param pagination
	 * @return
	 */
	@RequestMapping("/getHostLargeList.do")
	public ModelAndView getHostLargeList(HttpServletRequest request,HttpServletResponse response,Pagination pagination){
		ModelAndView model=new ModelAndView("/module/channel/hostlarge/hostlarge_list");
		return super.getDetail(request, response, model);
	}
	
	/**
	 * 查询大商户信息json数据
	 * @param pagination
	 * @param channel_no
	 * @param hostLarge
	 * @param ins_cd
	 * @param ins_cn_nm
	 * @return
	 */
	@RequestMapping("/getHostLargeListJson.do")
	public @ResponseBody Map getHostLargeListJson(HttpServletRequest request,Pagination pagination,String channel_no,App_Host_LargeEntity hostLarge,
			String ins_cd,String ins_cn_nm){
		if(StringUtils.isBlank(channel_no)){
			return new HashMap();
		}
		Map channel=infChannelService.getTableNameByParam(channel_no);
		if(channel==null || channel.size()<1){
			return new HashMap();
		}
		String tableName=(String)channel.get("chn_prmtb");
		if(StringUtils.isBlank(tableName)){
			return new HashMap();
		}
		return hostLargeService.getHostLargeList(request,pagination, hostLarge, ins_cd, ins_cn_nm, tableName, channel_no);		 
	}
	
	/**
	 * 进入大商户信息详细页面
	 * @param request
	 * @param response
	 * @param pagination
	 * @param host_large_uuid
	 * @param channel_no
	 * @return
	 */
	@RequestMapping("/getHostLargeDetail.do")
	public ModelAndView getHostLargeDetail(HttpServletRequest request,HttpServletResponse response,Pagination pagination,
			String host_large_uuid,String channel_no){
		ModelAndView model=new ModelAndView("/module/channel/hostlarge/hostlarge_detail");
		Map channel=infChannelService.getTableNameByParam(channel_no);	
		String tableName=String.valueOf(channel.get("chn_prmtb"));
		Map hostLarge=hostLargeService.getHostLargeDetail(host_large_uuid, tableName, channel_no);
		model.addObject("hostLarge", hostLarge);
		model.addObject("channel_no", channel.get("channel_no"));
		model.addObject("chnname", channel.get("chnname"));
		return super.getDetail(request, response, model);
	}
	
	/**
	 * 保存大商户
	 * @param request
	 * @param response
	 * @param hostLarge
	 * @param channel_no
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("/saveHostLarge.do")
	public ModelAndView saveHostLarge(HttpServletRequest request,HttpServletResponse response,App_Host_LargeEntity hostLarge,
			String channel_no){
		Map channel=infChannelService.getTableNameByParam(channel_no);	
		String tableName=String.valueOf(channel.get("chn_prmtb"));
		hostLargeService.saveHostLarge(hostLarge, super.getLoginUser(request, response), tableName,channel_no);
		Map map=super.getLoginUser(request, response);  
		return new ModelAndView(new RedirectView("getHostLargeList.do"), map);
	}
	
	/**
	 * 删除
	 * @param request
	 * @param response
	 * @param host_large_uuids
	 * @param channel_no
	 * @return
	 */
	@RequestMapping("/deleteHostLargeByIds.do")
	public ModelAndView deleteHostLargeByIds(HttpServletRequest request,HttpServletResponse response,String host_large_uuids,
			String channel_no){
		Map channel=infChannelService.getTableNameByParam(channel_no);	
		String tableName=String.valueOf(channel.get("chn_prmtb"));
		hostLargeService.deleteHostLargeByIds(host_large_uuids, tableName);
		Map map=super.getLoginUser(request, response);  
		return new ModelAndView(new RedirectView("getHostLargeList.do"), map);
	}
	
	/**
	 * 校验大商户
	 * @param hostLarge
	 * @param channel_no
	 * @return
	 */
	@RequestMapping("/checkHostLarge.do")
	public @ResponseBody String checkHostLarge(App_Host_LargeEntity hostLarge,String channel_no){	
		Map channel=infChannelService.getTableNameByParam(channel_no);			
		String tableName=String.valueOf(channel.get("chn_prmtb"));
		return hostLargeService.checkHostLarge(hostLarge,tableName);
	}

}
